/*     */ package com.hp.bon.sgw.service;
/*     */ 
/*     */ import com.hp.bon.sgw.bean.SysPertriNetBean;
/*     */ import com.hp.bon.sgw.ctrl.PetriExecutor;
/*     */ import com.hp.bon.sgw.domain.ProcessLog;
/*     */ import com.hp.bon.sgw.snmp.SGWMibSetter;
/*     */ import com.hp.bon.sgw.threads.ProcessLogCacheManager;
/*     */ import java.net.SocketAddress;
/*     */ import java.sql.Timestamp;
/*     */ import java.util.Date;
/*     */ import org.productivity.java.syslog4j.server.SyslogServerEventIF;
/*     */ import org.productivity.java.syslog4j.server.SyslogServerIF;
/*     */ import org.productivity.java.syslog4j.server.SyslogServerSessionEventHandlerIF;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ 
/*     */ public class SyslogFilterEventHandler
/*     */   implements SyslogServerSessionEventHandlerIF
/*     */ {
/*  29 */   public static final Logger logger = LoggerFactory.getLogger("SYSLOG_WRITER");
/*     */   private SGWMibSetter sgwMibSetter;
/*     */   private PetriExecutor petriExecutor;
/*     */   private static final long serialVersionUID = -4772548122997401981L;
/*  54 */   private static int oldstatus = -1;
/*  55 */   private static int newstatus = -1;
/*     */ 
/*     */   public void initialize(SyslogServerIF syslogServer)
/*     */   {
/*     */   }
/*     */ 
/*     */   public void destroy(SyslogServerIF syslogServer)
/*     */   {
/*     */   }
/*     */ 
/*     */   public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress)
/*     */   {
/*  51 */     return null;
/*     */   }
/*     */ 
/*     */   public void event(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, SyslogServerEventIF event)
/*     */   {
/*  63 */     String syslogMsg = event.getMessage();
/*  64 */     switch (event.getLevel()) {
/*     */     case 7:
/*  66 */       if (logger.isDebugEnabled())
/*  67 */         logger.debug(syslogMsg);
/*  68 */       break;
/*     */     case 6:
/*  71 */       if (logger.isInfoEnabled())
/*  72 */         logger.info(syslogMsg);
/*  73 */       break;
/*     */     case 4:
/*     */     case 5:
/*  77 */       if (logger.isWarnEnabled())
/*  78 */         logger.warn(syslogMsg);
/*  79 */       break;
/*     */     case 1:
/*     */     case 2:
/*     */     case 3:
/*  84 */       logger.error(syslogMsg);
/*     */     }
/*     */ 
/*  88 */     filterLogMessage(event);
/*     */   }
/*     */ 
/*     */   private void filterLogMessage(SyslogServerEventIF event)
/*     */   {
/*  97 */     String syslogMsg = event.getMessage();
/*     */ 
/* 100 */     ProcessLog log = null;
/*     */     try {
/* 102 */       if ((syslogMsg != null) && (!"".equals(syslogMsg))) {
/* 103 */         String[] messages = syslogMsg.split("\\|");
/* 104 */         if (messages.length >= 4)
/* 105 */           if (messages[3].equals("sgwstatuschanged")) {
/* 106 */             if ((Integer.valueOf(messages[4]).intValue() == -4) || (Integer.valueOf(messages[4]).intValue() == -6)) {
/* 107 */               newstatus = Integer.valueOf(messages[5]).intValue(); } else {
/* 108 */               if ((Integer.valueOf(messages[5]).intValue() == -4) || (Integer.valueOf(messages[5]).intValue() == -6)) {
/* 109 */                 oldstatus = Integer.valueOf(messages[4]).intValue();
/* 110 */                 return;
/*     */               }
/* 112 */               oldstatus = Integer.valueOf(messages[4]).intValue();
/* 113 */               newstatus = Integer.valueOf(messages[5]).intValue();
/*     */             }
/* 115 */             log = new ProcessLog();
/* 116 */             log.setLogType("StatusChange");
/* 117 */             log.setLogLevel(4);
/* 118 */             log.setErrorCode(SysPertriNetBean.getChangeCode(oldstatus, newstatus));
/* 119 */             log.setErrorName("system status changed");
/* 120 */             log.setExpertAdvice("check system status");
/* 121 */             log.setContent("status changed from " + SysPertriNetBean.getPertiStatusName(oldstatus) + " to " + SysPertriNetBean.getPertiStatusName(newstatus));
/* 122 */             log.setLogTime(new Timestamp(System.currentTimeMillis()));
/* 123 */             ProcessLogCacheManager.getInstance().add(log);
/*     */ 
/* 125 */             this.sgwMibSetter.notifySGWStatesChanged(oldstatus, newstatus, event.getDate().getTime() / 1000L);
/* 126 */           } else if (messages[3].equals("msgprocesserror")) {
/* 127 */             log = new ProcessLog();
/* 128 */             log.setLogType("ProcessLog");
/* 129 */             log.setLogLevel(1);
/* 130 */             log.setErrorCode(17006);
/* 131 */             log.setErrorName("SGW message process exception");
/* 132 */             log.setExpertAdvice("check SGW message process");
/* 133 */             log.setContent("SGW message process is error");
/* 134 */             log.setLogTime(new Timestamp(System.currentTimeMillis()));
/* 135 */             ProcessLogCacheManager.getInstance().add(log);
/* 136 */             this.sgwMibSetter.notifyMsgError(1, "SGW message process is error", event.getDate().getTime() / 1000L);
/* 137 */           } else if (messages[3].equals("fileprocesserror")) {
/* 138 */             log = new ProcessLog();
/* 139 */             log.setLogType("ProcessLog");
/* 140 */             log.setLogLevel(1);
/* 141 */             log.setErrorCode(17007);
/* 142 */             log.setErrorName("SGW " + messages[4] + " process exception");
/* 143 */             log.setExpertAdvice("check SGW CTP process");
/* 144 */             log.setContent("SGW CTP process is error");
/* 145 */             log.setLogTime(new Timestamp(System.currentTimeMillis()));
/* 146 */             ProcessLogCacheManager.getInstance().add(log);
/*     */ 
/* 148 */             this.sgwMibSetter.notifyfileError("SGW " + messages[4] + " process is error", event.getDate().getTime() / 1000L);
/* 149 */           } else if ((messages[3].equals("connectionfull")) && (messages.length >= 5)) {
/* 150 */             this.sgwMibSetter.notifyInterfaceConnectsCntMax(Integer.valueOf(messages[4]).intValue(), event.getDate().getTime() / 1000L);
/* 151 */           } else if ((messages[3].equals("fluxcontrlwarn")) && (messages.length >= 11)) {
/* 152 */             this.sgwMibSetter.notifyFlowSizeAlert(messages[5], messages[6], messages[7], Integer.valueOf(messages[8]).intValue(), Long.valueOf(messages[9]).longValue(), messages[10], event.getDate().getTime() / 1000L);
/* 153 */           } else if ((messages[3].equals("congestionchanged")) && (messages.length >= 7)) {
/* 154 */             int oldLevel = Integer.valueOf(messages[5]).intValue();
/* 155 */             int newLevel = Integer.valueOf(messages[6]).intValue();
/* 156 */             this.sgwMibSetter.notifyBlockChanged(oldLevel, newLevel, event.getDate().getTime() / 1000L);
/* 157 */             if (this.petriExecutor != null)
/* 158 */               this.petriExecutor.onCongestionLevelChanged(oldLevel, newLevel);
/*     */           }
/* 160 */           else if ((messages[3].equals("linkexception")) && (messages.length >= 7)) {
/* 161 */             this.sgwMibSetter.notifyInterfaceRunningError(messages[5], 0, messages[6], event.getDate().getTime() / 1000L); } else {
/* 162 */             messages[3].equals("processlog");
/*     */           }
/*     */       }
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 168 */       logger.warn("process syslog error:" + e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void exception(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception)
/*     */   {
/* 174 */     exception.printStackTrace();
/* 175 */     logger.warn("syslog exception:from socket " + socketAddress + " detail:" + exception.toString());
/*     */   }
/*     */ 
/*     */   public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout)
/*     */   {
/*     */   }
/*     */ 
/*     */   @Autowired
/*     */   public void setSgwMibSetter(SGWMibSetter sgwMibSetter)
/*     */   {
/* 191 */     this.sgwMibSetter = sgwMibSetter;
/*     */   }
/*     */ 
/*     */   public void setPetriExecutor(PetriExecutor petriExecutor) {
/* 195 */     this.petriExecutor = petriExecutor;
/*     */   }
/*     */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.sgw.service.SyslogFilterEventHandler
 * JD-Core Version:    0.6.1
 */